package android.hci.extractor;

import org.mmi.android.instrumentation.InstrumentationContext;

import android.app.Activity;
import android.hci.extractor.test.R;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class testActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		//set elements to the spinner
		Spinner spinner = (Spinner) findViewById(R.id.spinner1);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
				this, R.array.test_array, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);

		//set generic listener to display text
		//findViewById(R.id.bExit).setOnClickListener(gocl);
		findViewById(R.id.button1).setOnClickListener(gocl);
		findViewById(R.id.checkBox1).setOnClickListener(gocl);
		findViewById(R.id.checkBox2).setOnClickListener(gocl);
		findViewById(R.id.editText1).setOnClickListener(gocl); 
		findViewById(R.id.label).setOnClickListener(gocl);
		findViewById(R.id.radioButton1).setOnClickListener(gocl);
		findViewById(R.id.seekBar1).setOnClickListener(gocl);
		spinner.setOnItemSelectedListener(goisl);

		///
		///
		/// exit button listener
		findViewById(R.id.bExit).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		/// ///////////////////////////////////////////////////////////////
		/// instrumentation
		/// ///////////////////////////////////////////////////////////////
		///
		try {
			//reset the instrumentation context
			InstrumentationContext.reset(new YourFacade());
			//register this activity as the main activity
			InstrumentationContext.get().registerMainActivity(this);
			//start interaction tracking
			InstrumentationContext.get().startInteraction(); 
			//} catch (InstrumentationException e) {
		} catch (Exception e) {
			e.printStackTrace();
		}
		/// 
		/// ///////////////////////////////////////////////////////////////
	}

	///
	///
	///
	OnClickListener gocl = new OnClickListener() {
		public void onClick(View view) {
			TextView label = (TextView) findViewById(R.id.label);
			if (label != null)
				label.setText(view.toString());
		}
	};

	///
	///
	///
	OnItemSelectedListener goisl = new OnItemSelectedListener() {
		@Override
		public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
			TextView label = (TextView) findViewById(R.id.label);
			if (label != null)
				label.setText(selectedItemView.toString());
		}

		@Override
		public void onNothingSelected(AdapterView<?> parentView) {
			TextView label = (TextView) findViewById(R.id.label);
			if (label != null)
				label.setText(parentView.toString());
		}
	};

	///
	///
	///
	OnItemClickListener gicl = new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			TextView label = (TextView) findViewById(R.id.label);
			if (label != null)
				label.setText(arg1.toString());
		}
	};
}